@extends('admin.layouts.head')

@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('admin.layouts.navbar')
        @include('admin.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item active" aria-current="page">标签列表</li>
                            </ol>
                        </nav>
                        @verbatim
                        <div class="card">
                            <div class="card-body">

                                <div id="vueApp">
                                    <div class="content-box">

                                        <div class="op-bar" style="margin: 16px 0;">
                                            <el-button type="primary" @click="saveTag({id:0,tag_name: ''})" size="mini">添加</el-button>
                                        </div>

                                        <el-table
                                            :data="tagList"
                                            border
                                            size="mini"
                                            style="width: 100%">
                                            <el-table-column
                                                prop="id"
                                                label="ID"
                                                width="80"
                                            >
                                            </el-table-column>
                                            <el-table-column
                                                prop="tag_name"
                                                label="名称"
                                            >
                                            </el-table-column>
                                            <el-table-column
                                                label="操作"
                                                width="180"
                                            >
                                                <template slot-scope="scope">
                                                    <el-button @click="saveTag(scope.row)" type="primary" round plain size="small">编辑</el-button>
                                                    <el-button type="danger" round plain size="small" @click="delTag(scope.row.id)">删除</el-button>
                                                </template>
                                            </el-table-column>
                                        </el-table>

                                    </div>

                            </div> <!-- .card-body -->
                        </div> <!-- .card -->
                        @endverbatim
                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->

    @include('admin.layouts.vuehead')

    <script>
        const vueApp = new Vue({
            el: '#vueApp',
            data() {
                return {
                    tagList: [],
                }
            },
            mounted() {
                this.getTagList()
            },
            watch: {

            },
            methods: {
                getTagList() {
                    adminApi_getGameTagList().then(res => {
                        this.tagList = res.data
                    })
                },
                saveTag(tag) {
                    this.$prompt('请输入标签', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        inputValue: tag.tag_name,
                    }).then(({ value }) => {
                        adminApi_saveGameTag({id:tag.id, tag_name:value }).then(res => {
                            this.$message.success('保存成功')
                            this.getTagList()
                        }).catch(err => {
                            this.$message.error(err.message)
                        })
                    })
                },
                delTag(id) {
                    this.$confirm('确认删除吗?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        adminApi_delGameTag({id}).then(res => {
                            this.$message.success('删除成功')
                            this.getTagList()
                        })
                    }).catch(() => {});

                }
            },
        })
    </script>
    </body>


    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
    </style>
@endsection
